﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Net;
using System.IO;
namespace ProcessesSMS
{
    /// <summary>
    /// Summary description for CKVN.
    /// </summary>
    public class XACMINHHANGTHAT
    {

        private SMS_MO WMO;
        private SMS_MT WMT;
        //private SMS_LIST WML;
        ArrayList arr = new ArrayList();
        public XACMINHHANGTHAT(SMS_MO MO)
        {
            WMO = MO;
        }

        public XACMINHHANGTHAT()
        {
        }
        public void run()
        {
            WMT = new SMS_MT(WMO);
            string tmpMsg = WMO.Message.Substring(WMO.CommandCode.Length).Trim().Replace("  ", " ").Replace("  ", " ");
            tmpMsg = tmpMsg.Replace("  ", " ").Trim().ToUpper();
            string[] msg = tmpMsg.Split(new char[] { ' ' });
            string strReturnMsg = GetReturnMsg(WMO.MO_ID,"e6e800325d8a2da1b5b4dc824e1106c4",WMO.ServiceID,WMO.UserID,WMO.Message,GetTelcoName(WMO.UserID));
            //if (strReturnMsg != "")
            //{
           // string[] strReturnMsg = GetReturnMsg(msg).Split('|');
           // for (int i = 0; i < strReturnMsg.Length; i++)
           // {
                WMT.AddMessage(WMO.UserID, strReturnMsg, SMS_ContentType.SMS_TEXT);
                WMT.MsgType = SMS_MsgType.SMS_TINHTIEN;
            //}
            WMT.Insert();
            //}
            return;
        }
        private string GetReturnMsg(int moid,string macode,string serviceid,string userid,string messagett, string telcol)
        {
          string msgBody = string.Empty;                        
            
                SMSXacminhhangthat.SMS ws = new ProcessesSMS.SMSXacminhhangthat.SMS();
                msgBody = ws.XacMinhHangThatSMS(moid, macode, serviceid,userid, messagett, telcol);                
            
           
            
            return msgBody;
        }
        private string GetTelcoName(string phonenumber)
        {
            string str2number = phonenumber.Substring(2, 2);
            string str3number = phonenumber.Substring(2, 3);
            string telconame = "";
            if (str2number == "96" || str2number == "97" || str2number == "98" || str3number == "163" || str3number == "164" || str3number == "165" || str3number == "166" || str3number == "167" || str3number == "168" || str3number == "169")
                telconame = "VIETTEL";
            else if (str2number == "91" || str2number == "94" || str3number == "123" || str3number == "125" || str3number == "127" || str3number == "129")
                telconame = "VINAPHONE";
            else if (str2number == "90" || str2number == "93" || str3number == "120" || str3number == "121" || str3number == "122" || str3number == "126" || str3number == "128")
                telconame = "MOBIFONE";
            else if (str2number == "95")
                telconame = "SFONE";
            else if (str2number == "92" || str3number == "188")
                telconame = "VIETNAMOBILE";
            else if (str2number == "99" || str3number == "199")
                telconame = "BEELINE";
            else
                telconame = "Unname";
            return telconame;
        }
    }
}
